<!DOCTYPE html>
<html>
  <head>
    <script src="./node_modules/docx/build/index.umd.js"></script>
    <script src="./FileSaver.js"></script>
  </head>

  <body>
    <h1>矿山遥感监测</h1>

    <button type="button" id="button1">
        矿山遥感监测报告下载
    </button>

    <script>
      var arr1 = []
      var arr2 = []
      var completedRequests = 0;
      var xhr1 = new XMLHttpRequest()
      xhr1.responseType = "json"
      xhr1.open("GET", "http://192.168.1.105:8091/exceltoword/selectKsczshape?jcsj=2024Q3")
      xhr1.send()
      xhr1.onreadystatechange = function () {
        if (xhr1.readyState == 4 && xhr1.status == 200) {
          arr1 = xhr1.response
          completedRequests++;  
          if (completedRequests === 2) {  
              generate(arr1, arr2);  
          } 
        }
      }
      var xhr2 = new XMLHttpRequest()
      xhr2.responseType = "json"
      xhr2.open("GET", "http://192.168.1.105:8091/exceltoword/selectKsfqshape?jcsj=2024Q3")
      xhr2.send()
      xhr2.onreadystatechange = function () {
        if (xhr2.readyState == 4 && xhr2.status == 200) {
          arr2 = xhr2.response
          completedRequests++;  
          if (completedRequests === 2) {  
              generate(arr1, arr2);  
          } 
        }
      }
      function generate(arr1, arr2) {
        console.log(arr1, arr2)
        var mergedData1 = {};    
        arr1.forEach(item => {  
            if (!mergedData1[item.ksmc]) {   
                mergedData1[item.ksmc] = {  
                    cou: item.cou,  
                    ksmc: item.ksmc,
                    sczt: item.sczt,
                    area1: 0,  
                    count1: 0,  
                    area2: 0,  
                    count2: 0,  
                    area3: 0,  
                    count3: 0  
                };  
            }          
            switch (item.tblx) {  
                case "疑似越界":  
                    mergedData1[item.ksmc].area1 += parseFloat(item.area);  
                    mergedData1[item.ksmc].count1 += parseInt(item.count);  
                    break;  
                case "新增损毁":  
                    mergedData1[item.ksmc].area2 += parseFloat(item.area);  
                    mergedData1[item.ksmc].count2 += parseInt(item.count);  
                    break;  
                case "其他":  
                    mergedData1[item.ksmc].area3 += parseFloat(item.area);  
                    mergedData1[item.ksmc].count3 += parseInt(item.count);  
                    break;  
            }  
        });          
        var array1 = Object.values(mergedData1).map(obj => ({  
            ...obj,  
        }));
        console.log(array1)
        const couSums1 = {};
        const coutbsum1 = {};
        var ysyjsum1 = 0;
        var xzshsum1 = 0;
        var qtsum1 = 0;
        const fcqcou = "繁昌区";
        const nlxcou = "南陵县";
        const yjqcou = "弋江区";
        const wwscou = "无为市";
        const jjqcou = "鸠江区";
        const jhqcou = "镜湖区";
        const wzqcou = "湾沚区";
        array1.forEach(item => {
            if(item.area1 > 0){
              ysyjsum1++;
            }
            if(item.area2 > 0){
              xzshsum1++;
            }
            if(item.area3 > 0){
              qtsum1++;
            }
            const cou = item.cou;
            const area1 = parseFloat(item.area1);
            const area2 = parseFloat(item.area2);
            const area3 = parseFloat(item.area3);
            
            if (!(cou in couSums1)) {
                couSums1[cou] = { area1: 0, area2: 0, area3: 0,count1: 0, count2: 0,count3: 0 ,cou: item.cou};
            }
            couSums1[cou].count1 += item.count1;
            couSums1[cou].count2 += item.count2;
            couSums1[cou].count3 += item.count3;
            couSums1[cou].area1 += area1;
            couSums1[cou].area2 += area2;
            couSums1[cou].area3 += area3; 
        });
        var text_para1= "";
        const couSumkey1 = Object.keys(couSums1);
        for (let key of couSumkey1) {
            // console.log(key, couSums2[key]);
            text_para1 += couSums1[key].cou + "\“疑似越界\”图斑" + couSums1[key].count1 + "个,图斑面积" + parseFloat(couSums1[key].area1).toFixed(1) + "亩；"
                          + "\“新增损毁\”图斑" + couSums1[key].count2 + "个，图斑面积" + parseFloat(couSums1[key].area2).toFixed(1) + "亩；"
                          + "\“其他\”图斑" + couSums1[key].count3 + "个，图斑面积" + parseFloat(couSums1[key].area3).toFixed(1) + "亩；";
        }
        console.log(text_para1);



        // 创建一个新数组来存储结果
        const newData1 = [];
          
        // 遍历原始数组，将每个项添加到新数组中，并在每个cou的最后添加总计项
        array1.forEach(item => {
            newData1.push({ ...item }); // 使用{ ...item }创建对象的浅拷贝，以避免直接修改原始数组项
            const cou = item.cou;
            // 检查是否已经添加了该cou的总计项（通过查找town为"总计"且cou相同的项）
            const hasTotal = newData1.some(x => x.ksmc === "总计" && x.cou === cou);
            if (!hasTotal) {
                const totalItem = {
                    cou: cou,
                    sczt:"",
                    area1: couSums1[cou].area1, 
                    area2: couSums1[cou].area2,
                    area3: couSums1[cou].area3,
                    ksmc: "总计",
                };
                newData1.push(totalItem);
            }
        });
          
        // 按照cou的顺序排序，并确保总计项在每个cou的最后
        const sortedNewData1 = [];
        const couOrder1 = [...new Set(array1.map(item => item.cou))].sort((a, b) => a.localeCompare(b));
          
        couOrder1.forEach(cou => {
            const couItems = newData1.filter(item => item.cou === cou);
            const nonTotalItems = couItems.filter(item => item.ksmc !== "总计");
            const totalItem = couItems.find(item => item.ksmc === "总计");
            
            sortedNewData1.push(...nonTotalItems);
            if (totalItem) {
                sortedNewData1.push(totalItem);
            }
        });
        console.log(sortedNewData1);

        var mergedData2 = {};    
        arr2.forEach(item => {  
            if (!mergedData2[item.xmmc]) {   
                mergedData2[item.xmmc] = {  
                    cou: item.cou,  
                    xmmc: item.xmmc,
                    sfzl: item.sfzl,
                    area1: 0,  
                    count1: 0,  
                    area2: 0,  
                    count2: 0,  
                    area3: 0,  
                    count3: 0,  
                    area4: 0,  
                    count4: 0,
                };  
            }          
            switch (item.tblx) {  
                case "植被破坏":  
                    mergedData2[item.xmmc].area1 += parseFloat(item.area);  
                    mergedData2[item.xmmc].count1 += parseInt(item.count);  
                    break;  
                case "疑似越界":  
                    mergedData2[item.xmmc].area2 += parseFloat(item.area);  
                    mergedData2[item.xmmc].count2 += parseInt(item.count);  
                    break;  
                case "疑似偷盗采":  
                    mergedData2[item.xmmc].area3 += parseFloat(item.area);  
                    mergedData2[item.xmmc].count3 += parseInt(item.count);  
                    break; 
                case "其他":  
                    mergedData2[item.xmmc].area4 += parseFloat(item.area);  
                    mergedData2[item.xmmc].count4 += parseInt(item.count);  
                    break;  
            }  
        });          
        var array2 = Object.values(mergedData2).map(obj => ({  
            ...obj,  
        }));
        console.log(array2)
        const couSums2 = {};
        const coutbsum2 = {};
        var zbphsum2 = 0;
        var ysyjsum2 = 0;
        var ystdcsum2 = 0;
        var qtsum2 = 0;
        array2.forEach(item => {
            if(item.area1 > 0){
              zbphsum2++;
            }
            if(item.area2 > 0){
              ysyjsum2++;
            }
            if(item.area3 > 0){
              ystdcsum2++;
            }
            if(item.area4 > 0){
              qtsum2++;
            }
            const cou = item.cou;
            const area1 = parseFloat(item.area1);
            const area2 = parseFloat(item.area2);
            const area3 = parseFloat(item.area3);
            const area4 = parseFloat(item.area4);
            
            if (!(cou in couSums2)) {
                couSums2[cou] = { area1: 0, area2: 0, area3: 0, area4: 0 ,count1: 0,count2: 0, count3: 0, count4: 0 ,cou: item.cou};
            }

            couSums2[cou].area1 += area1;
            couSums2[cou].area2 += area2;
            couSums2[cou].area3 += area3; 
            couSums2[cou].area4 += area4; 
            couSums2[cou].count1 += item.count1;
            couSums2[cou].count2 += item.count2;
            couSums2[cou].count3 += item.count3;
            couSums2[cou].count4 += item.count4;
        });
        var text_para2 = "";
        const couSumkey2 = Object.keys(couSums2);
        for (let key of couSumkey2) {
            // console.log(key, couSums2[key]);
            text_para2 += couSums2[key].cou + "\“植被破坏\”图斑" + couSums2[key].count1 + "个,图斑面积" + parseFloat(couSums2[key].area1).toFixed(1) + "亩；"
                          + "\“疑似越界\”图斑" + couSums2[key].count2 + "个，图斑面积" + parseFloat(couSums2[key].area2).toFixed(1) + "亩；"
                          + "\“疑似偷盗采\”图斑" + couSums2[key].count3 + "个，图斑面积" + parseFloat(couSums2[key].area3).toFixed(1) + "亩；"
                          + "\“其他\”图斑" + couSums2[key].count4 + "个，图斑面积" + parseFloat(couSums2[key].area4).toFixed(1) + "亩；";
        }
        // console.log(text_para2);
        
        // 创建一个新数组来存储结果
        const newData2 = [];
        
        // 遍历原始数组，将每个项添加到新数组中，并在每个cou的最后添加总计项
        array2.forEach(item => {
            newData2.push({ ...item }); // 使用{ ...item }创建对象的浅拷贝，以避免直接修改原始数组项
            const cou = item.cou;
            // 检查是否已经添加了该cou的总计项（通过查找town为"总计"且cou相同的项）
            const hasTotal = newData2.some(x => x.xmmc === "总计" && x.cou === cou);
            if (!hasTotal) {
                const totalItem = {
                    cou: cou,
                    area1: couSums2[cou].area1, 
                    area2: couSums2[cou].area2,
                    area3: couSums2[cou].area3,
                    area4: couSums2[cou].area4,
                    xmmc: "总计",
                };
                newData2.push(totalItem);
            }
        });
          
        // 按照cou的顺序排序，并确保总计项在每个cou的最后
        const sortedNewData2 = [];
        const couOrder2 = [...new Set(array2.map(item => item.cou))].sort((a, b) => a.localeCompare(b));
          
        couOrder2.forEach(cou => {
            const couItems = newData2.filter(item => item.cou === cou);
            const nonTotalItems = couItems.filter(item => item.xmmc !== "总计");
            const totalItem = couItems.find(item => item.xmmc === "总计");
            
            sortedNewData2.push(...nonTotalItems);
            if (totalItem) {
                sortedNewData2.push(totalItem);
            }
        });
        console.log(sortedNewData2);

        var scsumcount1 = 0
        var scsumarea1 = 0
        var scsumcount2 = 0
        var scsumarea2 = 0
        var scsumcount3 = 0
        var scsumarea3 = 0
        array1.reduce((accumulator, item) => {  
            scsumcount1 += parseInt(item.count1, 10); 
            scsumarea1 += parseFloat(item.area1); 
            scsumcount2 += parseInt(item.count2, 10); 
            scsumarea2 += parseFloat(item.area2); 
            scsumcount3 += parseInt(item.count3, 10); 
            scsumarea3 += parseFloat(item.area3); 
        }, {});

        var tcsumcount1 = 0
        var tcsumarea1 = 0
        var tcsumcount2 = 0
        var tcsumarea2 = 0
        var tcsumcount3 = 0
        var tcsumarea3 = 0
        var tcsumcount4 = 0
        var tcsumarea4 = 0
        array2.reduce((accumulator, item) => {  
            tcsumcount1 += parseInt(item.count1, 10); 
            tcsumarea1 += parseFloat(item.area1); 
            tcsumcount2 += parseInt(item.count2, 10); 
            tcsumarea2 += parseFloat(item.area2); 
            tcsumcount3 += parseInt(item.count3, 10); 
            tcsumarea3 += parseFloat(item.area3); 
            tcsumcount4 += parseInt(item.count4, 10); 
            tcsumarea4 += parseFloat(item.area4);
        }, {});

        var rows1 = [
            new docx.TableRow({
                children: [
                  new docx.TableCell({
                    children: [new docx.Paragraph({ text: "区县" }),],
                    verticalAlign: docx.VerticalAlign.CENTER,
                  }),
                  new docx.TableCell({
                    children: [new docx.Paragraph({ text: "矿山名称" }),],
                    verticalAlign: docx.VerticalAlign.CENTER,
                  }),
                  new docx.TableCell({
                    children: [
                      new docx.Paragraph({ text: "生产状态" }),
                    ],
                    verticalAlign: docx.VerticalAlign.CENTER,
                  }),
                  new docx.TableCell({
                      children: [
                      new docx.Paragraph({ text: "疑似越界" }),
                    ],
                    verticalAlign: docx.VerticalAlign.CENTER,
                  }),
                  new docx.TableCell({
                      children: [
                      new docx.Paragraph({ text: "新增损毁" }),
                    ],
                    verticalAlign: docx.VerticalAlign.CENTER,
                  }),
                  new docx.TableCell({
                      children: [
                      new docx.Paragraph({ text: "其他" }),
                    ],
                    verticalAlign: docx.VerticalAlign.CENTER,
                  }),
                  new docx.TableCell({
                      children: [
                      new docx.Paragraph({ text: "总计（亩）" }),
                    ],
                    verticalAlign: docx.VerticalAlign.CENTER,
                  }),
                ],
            }),
        ]
        sortedNewData1.forEach(item => {  
            rows1.push(new docx.TableRow({  
                children: [  
                    new docx.TableCell({  
                        children: [new docx.Paragraph({ text: `${item.cou}` })],  
                        verticalAlign: docx.VerticalAlign.CENTER,  
                    }),  
                    new docx.TableCell({  
                        children: [new docx.Paragraph({ text: `${item.ksmc}` })],  
                        verticalAlign: docx.VerticalAlign.CENTER,  
                    }),  
                    new docx.TableCell({  
                        children: [new docx.Paragraph({ text: `${item.sczt}` })],  
                        verticalAlign: docx.VerticalAlign.CENTER,  
                    }),
                    new docx.TableCell({  
                        children: [new docx.Paragraph({ text: `${parseFloat(item.area1).toFixed(1)}` })],  
                        verticalAlign: docx.VerticalAlign.CENTER,  
                    }),  
                    new docx.TableCell({  
                        children: [new docx.Paragraph({ text: `${parseFloat(item.area2).toFixed(1)}` })],  
                        verticalAlign: docx.VerticalAlign.CENTER,  
                    }),
                    new docx.TableCell({  
                        children: [new docx.Paragraph({ text: `${parseFloat(item.area3).toFixed(1)}` })],  
                        verticalAlign: docx.VerticalAlign.CENTER,  
                    }),
                    new docx.TableCell({  
                        children: [new docx.Paragraph({ text: `${parseFloat(item.area1 + item.area2 + item.area3).toFixed(1)}` })],  
                        verticalAlign: docx.VerticalAlign.CENTER,  
                    }),
                ],  
            }));  
        });
        rows1.push(new docx.TableRow({  
            children: [  
                new docx.TableCell({  
                    children: [new docx.Paragraph({ text: "总计" })],  
                    verticalAlign: docx.VerticalAlign.CENTER,  
                }),  
                new docx.TableCell({  
                    children: [new docx.Paragraph({ text: `` })],  
                    verticalAlign: docx.VerticalAlign.CENTER,  
                }),
                new docx.TableCell({  
                    children: [new docx.Paragraph({ text: `` })],  
                    verticalAlign: docx.VerticalAlign.CENTER,  
                }),
                new docx.TableCell({  
                    children: [new docx.Paragraph({ text: `${parseFloat(scsumarea1).toFixed(1)}` })],  
                    verticalAlign: docx.VerticalAlign.CENTER,  
                }),
                new docx.TableCell({  
                    children: [new docx.Paragraph({ text: `${parseFloat(scsumarea2).toFixed(1)}` })],  
                    verticalAlign: docx.VerticalAlign.CENTER,  
                }),
                new docx.TableCell({  
                    children: [new docx.Paragraph({ text: `${parseFloat(scsumarea3).toFixed(1)}` })],  
                    verticalAlign: docx.VerticalAlign.CENTER,  
                }),
                new docx.TableCell({  
                    children: [new docx.Paragraph({ text: `${parseFloat(scsumarea1 + scsumarea2 + scsumarea3).toFixed(1)}` })],  
                    verticalAlign: docx.VerticalAlign.CENTER,  
                }),
            ],  
        }));
        var rows2 = [
            new docx.TableRow({
                children: [
                  new docx.TableCell({
                    children: [new docx.Paragraph({ text: "区县" }),],
                    verticalAlign: docx.VerticalAlign.CENTER,
                  }),
                  new docx.TableCell({
                    children: [new docx.Paragraph({ text: "项目名称" }),],
                    verticalAlign: docx.VerticalAlign.CENTER,
                  }),
                  new docx.TableCell({
                    children: [
                      new docx.Paragraph({ text: "是否治理" }),
                    ],
                    verticalAlign: docx.VerticalAlign.CENTER,
                  }),
                  new docx.TableCell({
                      children: [
                      new docx.Paragraph({ text: "植被破坏" }),
                    ],
                    verticalAlign: docx.VerticalAlign.CENTER,
                  }),
                  new docx.TableCell({
                      children: [
                      new docx.Paragraph({ text: "疑似越界" }),
                    ],
                    verticalAlign: docx.VerticalAlign.CENTER,
                  }),
                  new docx.TableCell({
                      children: [
                      new docx.Paragraph({ text: "疑似偷盗采" }),
                    ],
                    verticalAlign: docx.VerticalAlign.CENTER,
                  }),
                  new docx.TableCell({
                      children: [
                      new docx.Paragraph({ text: "其他" }),
                    ],
                    verticalAlign: docx.VerticalAlign.CENTER,
                  }),
                  new docx.TableCell({
                      children: [
                      new docx.Paragraph({ text: "总计" }),
                    ],
                    verticalAlign: docx.VerticalAlign.CENTER,
                  }),
                ],
            }),
        ]
        sortedNewData2.forEach(item => {  
            rows2.push(new docx.TableRow({  
                children: [  
                    new docx.TableCell({  
                        children: [new docx.Paragraph({ text: `${item.cou}` })],  
                        verticalAlign: docx.VerticalAlign.CENTER,  
                    }),  
                    new docx.TableCell({  
                        children: [new docx.Paragraph({ text: `${item.xmmc}` })],  
                        verticalAlign: docx.VerticalAlign.CENTER,  
                    }),  
                    new docx.TableCell({  
                        children: [new docx.Paragraph({ text: `${item.sfzl}` })],  
                        verticalAlign: docx.VerticalAlign.CENTER,  
                    }),
                    new docx.TableCell({  
                        children: [new docx.Paragraph({ text: `${parseFloat(item.area1).toFixed(1)}` })],  
                        verticalAlign: docx.VerticalAlign.CENTER,  
                    }),  
                    new docx.TableCell({  
                        children: [new docx.Paragraph({ text: `${parseFloat(item.area2).toFixed(1)}` })],  
                        verticalAlign: docx.VerticalAlign.CENTER,  
                    }),
                    new docx.TableCell({  
                        children: [new docx.Paragraph({ text: `${parseFloat(item.area3).toFixed(1)}` })],  
                        verticalAlign: docx.VerticalAlign.CENTER,  
                    }),
                    new docx.TableCell({  
                        children: [new docx.Paragraph({ text: `${parseFloat(item.area4).toFixed(1)}` })],  
                        verticalAlign: docx.VerticalAlign.CENTER,  
                    }),
                    new docx.TableCell({  
                        children: [new docx.Paragraph({ text: `${parseFloat(item.area1 + item.area2 + item.area3 + item.area4).toFixed(1)}` })],  
                        verticalAlign: docx.VerticalAlign.CENTER,  
                    }),
                ],  
            }));  
        });
        rows2.push(new docx.TableRow({  
            children: [  
                new docx.TableCell({  
                    children: [new docx.Paragraph({ text: "总计" })],  
                    verticalAlign: docx.VerticalAlign.CENTER,  
                }),  
                new docx.TableCell({  
                    children: [new docx.Paragraph({ text: `` })],  
                    verticalAlign: docx.VerticalAlign.CENTER,  
                }),
                new docx.TableCell({  
                    children: [new docx.Paragraph({ text: `` })],  
                    verticalAlign: docx.VerticalAlign.CENTER,  
                }),
                new docx.TableCell({  
                    children: [new docx.Paragraph({ text: `${parseFloat(tcsumarea1).toFixed(1)}` })],  
                    verticalAlign: docx.VerticalAlign.CENTER,  
                }),
                new docx.TableCell({  
                    children: [new docx.Paragraph({ text: `${parseFloat(tcsumarea2).toFixed(1)}` })],  
                    verticalAlign: docx.VerticalAlign.CENTER,  
                }),
                new docx.TableCell({  
                    children: [new docx.Paragraph({ text: `${parseFloat(tcsumarea3).toFixed(1)}` })],  
                    verticalAlign: docx.VerticalAlign.CENTER,  
                }),
                new docx.TableCell({  
                    children: [new docx.Paragraph({ text: `${parseFloat(tcsumarea1 + tcsumarea2 + tcsumarea3 + tcsumarea4).toFixed(1)}` })],  
                    verticalAlign: docx.VerticalAlign.CENTER,  
                }),
            ],  
        }));
        console.log(parseFloat(scsumarea2).toFixed(1));
        const tubansum = scsumcount1+scsumcount2+scsumcount3+tcsumcount1+tcsumcount2+tcsumcount3+tcsumcount4;
        const areasum = scsumarea1+scsumarea2+scsumarea3+tcsumarea1+tcsumarea2+tcsumarea3+tcsumarea4;
        const chizhengsum = scsumcount1+scsumcount2+scsumcount3;
        const chizhengareasum = scsumarea1+scsumarea2+scsumarea3;
        const feiqisum = tcsumcount1+tcsumcount2+tcsumcount3+tcsumcount4;
        const feiqiareasum = tcsumarea1+tcsumarea2+tcsumarea3+tcsumarea4;

        const doc = new docx.Document({
          sections: [
            {
              children: [
                new docx.Paragraph({
                  text: "3.1成果分析",
                  heading: docx.HeadingLevel.HEADING_1,
                }),
                new docx.Paragraph({
                  text: `根据2024年第三季度安徽省芜湖市高分辨率遥感影像，经过解译分析，芜湖市范围内矿山变化遥感监测图斑${tubansum}个，图斑面积共${parseFloat(areasum).toFixed(1)}亩。按照矿山类型划分：持证矿山范围内监测图斑${chizhengsum}个，面积${parseFloat(chizhengareasum).toFixed(1)}亩；废弃矿山范围内监测图斑${feiqisum}个，面积${parseFloat(feiqiareasum).toFixed(1)}亩。`,
                }),
                new docx.Paragraph({
                  text: "表3-1芜湖市2024年第3季度矿山监测图斑统计",
                  heading: docx.HeadingLevel.HEADING_3,
                  alignment: docx.AlignmentType.CENTER,
                }),
                new docx.Table({
                  rows: [
                  new docx.TableRow({
                      children: [
                        new docx.TableCell({
                          children: [new docx.Paragraph({ text: "矿山类型" }),],
                          verticalAlign: docx.VerticalAlign.CENTER,
                        }),
                        new docx.TableCell({
                          children: [new docx.Paragraph({ text: "变化类型" }),],
                          verticalAlign: docx.VerticalAlign.CENTER,
                        }),
                        new docx.TableCell({
                          children: [
                            new docx.Paragraph({ text: "图斑个数" }),
                          ],
                          verticalAlign: docx.VerticalAlign.CENTER,
                        }),
                        new docx.TableCell({
                            children: [
                            new docx.Paragraph({ text: "图斑面积（亩）" }),
                          ],
                          verticalAlign: docx.VerticalAlign.CENTER,
                        }),
                      ],
                    }),
                    new docx.TableRow({
                      children: [
                        new docx.TableCell({
                          children: [new docx.Paragraph({ text: "持证矿山" }),],
                          verticalAlign: docx.VerticalAlign.CENTER,
                        }),
                        new docx.TableCell({
                          children: [new docx.Paragraph({ text: "疑似越界" }),],
                          verticalAlign: docx.VerticalAlign.CENTER,
                        }),
                        new docx.TableCell({
                          children: [
                            new docx.Paragraph({ text: `${scsumcount1}` }),
                          ],
                          verticalAlign: docx.VerticalAlign.CENTER,
                        }),
                        new docx.TableCell({
                            children: [
                            new docx.Paragraph({ text: `${parseFloat(scsumarea1).toFixed(1)}` }),
                          ],
                          verticalAlign: docx.VerticalAlign.CENTER,
                        }),
                      ],
                    }),
                    new docx.TableRow({
                      children: [
                        new docx.TableCell({
                          children: [new docx.Paragraph({ text: "持证矿山" }),],
                          verticalAlign: docx.VerticalAlign.CENTER,
                        }),
                        new docx.TableCell({
                          children: [new docx.Paragraph({ text: "新增损毁" }),],
                          verticalAlign: docx.VerticalAlign.CENTER,
                        }),
                        new docx.TableCell({
                          children: [
                            new docx.Paragraph({ text: `${scsumcount2}` }),
                          ],
                          verticalAlign: docx.VerticalAlign.CENTER,
                        }),
                        new docx.TableCell({
                            children: [
                            new docx.Paragraph({ text: `${parseFloat(scsumarea2).toFixed(1)}` }),
                          ],
                          verticalAlign: docx.VerticalAlign.CENTER,
                        }),
                      ],
                    }),
                    new docx.TableRow({
                      children: [
                        new docx.TableCell({
                          children: [new docx.Paragraph({ text: "持证矿山" }),],
                          verticalAlign: docx.VerticalAlign.CENTER,
                        }),
                        new docx.TableCell({
                          children: [new docx.Paragraph({ text: "其他" }),],
                          verticalAlign: docx.VerticalAlign.CENTER,
                        }),
                        new docx.TableCell({
                          children: [
                            new docx.Paragraph({ text: `${scsumcount3}` }),
                          ],
                          verticalAlign: docx.VerticalAlign.CENTER,
                        }),
                        new docx.TableCell({
                            children: [
                            new docx.Paragraph({ text: `${parseFloat(scsumarea3).toFixed(1)}` }),
                          ],
                          verticalAlign: docx.VerticalAlign.CENTER,
                        }),
                      ],
                    }),
                    new docx.TableRow({
                      children: [
                        new docx.TableCell({
                          children: [new docx.Paragraph({ text: "废弃矿山" }),],
                          verticalAlign: docx.VerticalAlign.CENTER,
                        }),
                        new docx.TableCell({
                          children: [new docx.Paragraph({ text: "植被破坏" }),],
                          verticalAlign: docx.VerticalAlign.CENTER,
                        }),
                        new docx.TableCell({
                          children: [
                            new docx.Paragraph({ text: `${tcsumcount1}` }),
                          ],
                          verticalAlign: docx.VerticalAlign.CENTER,
                        }),
                        new docx.TableCell({
                            children: [
                            new docx.Paragraph({ text: `${parseFloat(tcsumarea1).toFixed(1)}` }),
                          ],
                          verticalAlign: docx.VerticalAlign.CENTER,
                        }),
                      ],
                    }),
                    new docx.TableRow({
                      children: [
                        new docx.TableCell({
                          children: [new docx.Paragraph({ text: "废弃矿山）" }),],
                          verticalAlign: docx.VerticalAlign.CENTER,
                        }),
                        new docx.TableCell({
                          children: [new docx.Paragraph({ text: "疑似越界" }),],
                          verticalAlign: docx.VerticalAlign.CENTER,
                        }),
                        new docx.TableCell({
                          children: [
                            new docx.Paragraph({ text: `${tcsumcount2}` }),
                          ],
                          verticalAlign: docx.VerticalAlign.CENTER,
                        }),
                        new docx.TableCell({
                            children: [
                            new docx.Paragraph({ text: `${parseFloat(tcsumarea2).toFixed(1)}` }),
                          ],
                          verticalAlign: docx.VerticalAlign.CENTER,
                        }),
                      ],
                    }),
                    new docx.TableRow({
                      children: [
                        new docx.TableCell({
                          children: [new docx.Paragraph({ text: "废弃矿山" }),],
                          verticalAlign: docx.VerticalAlign.CENTER,
                        }),
                        new docx.TableCell({
                          children: [new docx.Paragraph({ text: "疑似偷盗采" }),],
                          verticalAlign: docx.VerticalAlign.CENTER,
                        }),
                        new docx.TableCell({
                          children: [
                            new docx.Paragraph({ text: `${tcsumcount3}` }),
                          ],
                          verticalAlign: docx.VerticalAlign.CENTER,
                        }),
                        new docx.TableCell({
                            children: [
                            new docx.Paragraph({ text: `${parseFloat(tcsumarea3).toFixed(1)}` }),
                          ],
                          verticalAlign: docx.VerticalAlign.CENTER,
                        }),
                      ],
                    }),
                    new docx.TableRow({
                      children: [
                        new docx.TableCell({
                          children: [new docx.Paragraph({ text: "废弃矿山" }),],
                          verticalAlign: docx.VerticalAlign.CENTER,
                        }),
                        new docx.TableCell({
                          children: [new docx.Paragraph({ text: "其他" }),],
                          verticalAlign: docx.VerticalAlign.CENTER,
                        }),
                        new docx.TableCell({
                          children: [
                            new docx.Paragraph({ text: `${tcsumcount4}` }),
                          ],
                          verticalAlign: docx.VerticalAlign.CENTER,
                        }),
                        new docx.TableCell({
                            children: [
                            new docx.Paragraph({ text: `${parseFloat(tcsumarea4).toFixed(1)}` }),
                          ],
                          verticalAlign: docx.VerticalAlign.CENTER,
                        }),
                      ],
                    }),
                  ]
                }),
                new docx.Paragraph({
                  text: "3.1.1持证矿山",
                  heading: docx.HeadingLevel.HEADING_2,
                }),
                new docx.Paragraph({
                  text: `持证矿山共(请手动填入)家，其中存在“疑似越界”行为的有${ysyjsum1}家，存在“新增损毁”的有${xzshsum1}家，存在“其他”行为的有${qtsum1}家。持证矿山范围内监测图斑${chizhengsum}个，面积${parseFloat(chizhengareasum).toFixed(1)}亩。其中“疑似越界”图斑${scsumcount1}个，图斑面积${parseFloat(scsumarea1).toFixed(1)}亩；“新增损毁”图斑${scsumcount2}个，面积${parseFloat(scsumarea2).toFixed(1)}亩；“其他”图斑${scsumcount3}个，面积${parseFloat(scsumarea3).toFixed(1)}亩。`,
                }),
                new docx.Paragraph({
                  text: `按区县划分` + text_para1,
                }),
                new docx.Paragraph({
                  text: "表3-2 芜湖市2024年第3季度持证矿山（生产）监测图斑分类统计",
                  heading: docx.HeadingLevel.HEADING_3,
                  alignment: docx.AlignmentType.CENTER,
                }),
                new docx.Table({
                  rows: rows1
                }),
                new docx.Paragraph({
                  text: "3.1.2废弃矿山",
                  heading: docx.HeadingLevel.HEADING_2,
                }),
                new docx.Paragraph({
                  text: `废弃矿山共(请手动填入)家，其中存在“植被破坏”行为的有${zbphsum2}家，存在“疑似偷盗采”行为的有${ystdcsum2}家，存在“疑似越界”行为的有${ysyjsum2}家，存在“其他”行为的有${qtsum2}家。废弃矿山范围内监测图斑${feiqisum}个，面积${parseFloat(feiqiareasum).toFixed(1)}亩。其中植被破坏图斑${tcsumcount1}个，面积${parseFloat(tcsumarea1).toFixed(1)}亩；疑似越界图斑${tcsumcount2}个，面积${parseFloat(tcsumarea2).toFixed(1)}亩；疑似偷盗采图斑${tcsumcount3}个，面积${parseFloat(tcsumarea3).toFixed(1)}亩；其他图斑${tcsumcount4}个，面积${parseFloat(tcsumarea4).toFixed(1)}亩。`,
                }),
                new docx.Paragraph({
                  text: `由监测结果来看，主要监测图斑集中在疑似越界。按区县划分，` + text_para2,
                }),
                new docx.Paragraph({
                  text: "表3-4 芜湖市2024年第3季度废弃矿山监测图斑分类统计",
                  heading: docx.HeadingLevel.HEADING_3,
                  alignment: docx.AlignmentType.CENTER,
                }),
                new docx.Table({
                  rows: rows2
                }),
              ],
            },
          ],
        });
        var button1 = document.getElementById("button1")
          button1.addEventListener("click", function () {
            docx.Packer.toBlob(doc).then((blob) => {
            console.log(blob);
            saveAs(blob, "矿山遥感监测报告.docx");
            console.log("Document created successfully");
          });
        })
      }

    </script>
  </body>
</html>
